package main

import (
	"fmt"
	"time"
)

func matrixReshape(mat [][]int, r int, c int) [][]int {
	m := len(mat)
	n := len(mat[0])

	// fmt.Println(mat[0])
	arrary := []int{}
	result := [][]int{}
	if m*n == r*c {
		for i := 0; i < r; i++ {
			for j := 0; j < c; j++ {
				// fmt.Println((c*i+j)/n, (c*i+j)%n)
				arrary = append(arrary, mat[(c*i+j)/n][(c*i+j)%n])
			}
			result = append(result, arrary[c*i:c*(i+1)])
		}
	} else {
		return mat
	}
	return result

}

func main() {
	start := time.Now()
	nums1 := [][]int{{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}}
	r := 5
	c := 3

	des := matrixReshape(nums1, r, c)

	cost := time.Since(start)
	fmt.Println(des)
	fmt.Println(cost)

}
